#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct POINT
{
	long long stu_num;
	char name[21];
	int x;
	int y;
	int z;
	int sum;
};

int down(const void *a,const void *b);
int main(void)
{
	int n;
	scanf("%d",&n);
	struct POINT p[n];
	for(int i=0;i<n;i++)
	{
		scanf("%lld %s %d%d%d",&p[i].stu_num,p[i].name,&p[i].x,&p[i].y,&p[i].z);
		p[i].sum=p[i].x+p[i].y+p[i].z;
	}
	
	qsort(p,n,sizeof(struct POINT),down);
	
	for(int i=0;i<n;i++)
	{
		printf("%lld %s %d %d %d %d\n",p[i].stu_num,p[i].name,p[i].x,p[i].y,p[i].z,p[i].sum);
	}
	return 0;
}
int down(const void *a,const void *b)
{
	struct POINT *s1=(struct POINT *)a;
	struct POINT *s2=(struct POINT *)b;
	if(s1->sum==s2->sum)
	{
		return strcmp(s1->name,s2->name);
	}
	else
	{
		return s2->sum-s1->sum;
	}
}
